package com.jzo2o.customer.controller.consumer;

import com.jzo2o.common.model.PageResult;
import com.jzo2o.customer.model.domain.AddressBook;
import com.jzo2o.customer.model.dto.request.AddressBookPageQueryReqDTO;
import com.jzo2o.customer.model.dto.request.AddressBookUpsertReqDTO;
import com.jzo2o.customer.service.IAddressBookService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Description AddressBookController
 * @Author luohai
 * @Date 2024-12-02
 */
@RestController("addressBookController")
@RequestMapping("/consumer/address-book")
@Api(tags = "用户端 - 普通用户地址相关接口")
public class AddressBookController {
    @Autowired
    private IAddressBookService addressBookService;

    /**
     * 新增地址
     * @param dto
     */
    @PostMapping
    @ApiOperation("新增地址")
    public void addAddress(@RequestBody AddressBookUpsertReqDTO dto){
        addressBookService.addAddress(dto);
    }

    /**
     * 地址簿分页查询
     * @param dto
     * @return
     */
    @GetMapping("/page")
    @ApiOperation("地址簿分页查询")
    public PageResult<AddressBook> addressBookPage(AddressBookPageQueryReqDTO dto){
        return addressBookService.addressBookPage(dto);
    }

    /**
     * 根据Id擦汗寻地址
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    @ApiOperation("根据Id查询地址")
    public AddressBook getAddressBookById(@PathVariable("id") Long id){
        return addressBookService.getAddressBookById(id);
    }

    /**
     * 根据Id修改地址
     * @param id
     * @return
     */
    @PutMapping("/{id}")
    @ApiOperation("根据Id修改地址")
    public void modifyAddressBookById(@PathVariable("id") Long id, @RequestBody AddressBookUpsertReqDTO dto){
        addressBookService.modifyAddressBookById(id,dto);
    }

    /**
     * 根据Id批量删除地址
     * @param ids
     */
    @DeleteMapping("/batch")
    @ApiOperation("根据Id批量删除地址")
    public void deleteAddressBookByIds(@RequestBody List<Long> ids){
        addressBookService.deleteAddressBookById(ids);
    }


    /**
     * 设置/取消默认地址
     * @param id
     * @param flag
     */
    @PutMapping("/default")
    @ApiOperation("设置/取消默认地址")
    public void defaultAddressBookById(Long id, Integer flag){
        addressBookService.defaultAddressBookById(id,flag);
    }

    /**
     * 获取默认地址接口
     * @return
     */
    @GetMapping("/defaultAddress")
    @ApiOperation("获取默认地址接口")
    public AddressBook defaultAddress(){
        return addressBookService.defaultAddress();
    }
}
